package com.emergency.engine.dao;

import com.emergency.engine.domain.ScenarPart;
import com.emergency.engine.domain.TimeLine;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by asus on 2020/3/13.
 */
public interface ScenarPartDao extends JpaRepository<ScenarPart,String>, JpaSpecificationExecutor<ScenarPart> {
    //查询当前ScenarPart片段库
    @Query(value ="select sp from ScenarPart sp where scenar.id=:scenarId")
    List<ScenarPart> findAllByScenarId(@Param("scenarId") Long scenarId);

    // 抽取进度片段进行查询
    @Query(value ="SELECT * FROM bus_scenar_part WHERE scenar_id=?1 AND start_time<?2 AND end_time>?2 AND if(?3>0,type=?3,1=1)", nativeQuery=true)
    List<ScenarPart> findByScenarAndTime(Long scenarId, Long curTime,int type);
}
